home *** CD-ROM | disk | FTP | other *** search
/ MacWorld 1996 March / MacWorld 03:96.toast / Graphics / clip2gif 0.7.2 / Scripting clip2gif / stat.perl < prev   
Text File  |  1995-12-01  |  3KB  |  104 lines

  1. #!/usr/bin/perl
  2. # Copyright 1995, Yves Piguet. All Rights Reserved.
  3.  
  4. # History:
  5. #  9/95: 1st release
  6. #  12/95: numeric sort instead of ascii sort; cleaned to run under Perl 5 (thanks to Philippe Chartrand)
  7.  
  8. # file names
  9.  
  10. $logfile = "MacHTTP.log";
  11. $loghtml = "stat.html";
  12.  
  13. ### processes the log file
  14.  
  15. open(inFile, $logfile);
  16.  
  17. for ($i = 0; $i < 24; $i++)
  18. {
  19.     $nHour[$i] = 0;
  20. }
  21.  
  22. while (<inFile>)
  23. {
  24.     SWITCH_ext:
  25.     {
  26.         if (/\.html\b/) { $nExt{"html"}++; last SWITCH_ext; }
  27.         if (/\.gif\b/) { $nExt{"gif"}++; last SWITCH_ext; }
  28.         if (/\.a?cgi\b/) { $nExt{"cgi"}++; last SWITCH_ext; }
  29.         $nExt{"other"}++;
  30.     }
  31.     
  32.     /\b(\d\d):\d\d/ && $nHour[$1]++;
  33.     
  34.     $total++;
  35. }
  36.  
  37. ### creates the graphics
  38.  
  39. $pieData = sprintf("{%.3f,red,%.3f,green,%.3f,blue,%.3f,yellow}",    # sum of data should be 360 to have a full pie
  40.     360 * $nExt{"html"} / $total,
  41.     360 * $nExt{"gif"} / $total,
  42.     360 * $nExt{"cgi"} / $total,
  43.     360 * $nExt{"other"} / $total);
  44.  
  45. $pie = "{chart data:" . $pieData . ", chart style:pie, position:{0,0,100,100}}";
  46.  
  47. $deflabelhtml = 'set html_label to {{rectangle:{110,15,120,25},color:red}, {drawn text:"html", position:{125,25}}}';
  48. $deflabelgif  = 'set gif_label to {{rectangle:{110,35,120,45},color:green}, {drawn text:"gif", position:{125,45}}}';
  49. $deflabelcgi  = 'set cgi_label to {{rectangle:{110,55,120,65},color:blue}, {drawn text:"cgi", position:{125,65}}}';
  50. $deflabelothr = 'set other_label to {{rectangle:{110,75,120,85},color:yellow}, {drawn text:"other", position:{125,85}}}';
  51.  
  52. ($maxHour) = reverse(sort({$b <=> $a} @nHour));    # rescales data in the range 0-100
  53. for ($i = 0; $i < 24; $i++)
  54. {
  55.     $nHour[$i] = int($nHour[$i]*100/$maxHour);
  56. }
  57. $bars = '{chart data:{' . join(',', @nHour) . '}, chart style:bars, thickness:5, position:{0,0,200,100}}';
  58.  
  59. &MacPerl'DoAppleScript(<<eof);    # executes what follows as an AppleScript script
  60. set red to {65535,0,0}
  61. set green to {0,65535,0}
  62. set blue to {0,0,65535}
  63. set yellow to {65535,65535,0}
  64. tell app \"clip2gif\"
  65.     $deflabelhtml
  66.     $deflabelgif
  67.     $deflabelcgi
  68.     $deflabelothr
  69.  set thePie to $pie
  70.     set theDrawingPie to {thePie} & html_label & gif_label & cgi_label & other_label
  71.     save {150,100} as GIF drawing theDrawingPie depth 4 colors palette system colors transparency first pixel in file \"extstats.gif\"
  72.     set theBars to $bars
  73.     save {200,100} as GIF drawing {theBars} depth 1 transparency first pixel in file \"hourlystats.gif\"
  74. end
  75. eof
  76.  
  77. ### writes the html doc
  78.  
  79. open(outFile, ">" . $loghtml);
  80.  
  81. print outFile <<eof    # writes what follows in the html doc
  82. <html>
  83. <head>
  84. <title>Stats</title>
  85. </head>
  86.  
  87. <body>
  88.  
  89. <h1>Stats</h1>
  90.  
  91. Total number of files: $total <p>
  92.  
  93. <h2>File Types Transmission Stats</h2>
  94.  
  95. <img src=extstats.gif><p>
  96.  
  97. <h2>Hourly Transmission Stats</h2>
  98.  
  99. <img src=hourlystats.gif><p>
  100.  
  101. </body>
  102. </html>
  103. eof
  104.